package 蓝桥真题;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class 左孩子右兄弟 {
       static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
       final static int N=100010;
       static int h[]=new int[N],e[]=new int[N],ne[]=new int[N],size[]=new int[N],idx,n;
       
       static void add(int a,int b){
    	      e[idx]=b;ne[idx]=h[a];h[a]=idx++;size[a]++;
       }
       static int dfs(int dot){
    	      int sum=0;
    	      for(int i=h[dot];i!=-1;i=ne[i]){
    	    	  sum=Math.max(sum,dfs(e[i])+size[dot]-1);
    	      }
    	      return sum+1;
       }
       public static void main(String[] args) throws IOException {
		      n=Integer.parseInt(br.readLine());
		      Arrays.fill(h, -1);
		      for(int i=2;i<=n;i++){
		    	  int f=Integer.parseInt(br.readLine());
		    	  add(f,i);
		      }
		      System.out.print(dfs(1)-1);
		      
	}
}
